const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const pathFn = url=>path.resolve(__dirname, url);
const outputPath = "dist";

module.exports = {
	entry: {
		"root":"./src/index.js"
  },
  plugins:[
    new HtmlWebpackPlugin({
      template: "./index.html"
    }),
    new CleanWebpackPlugin([outputPath]),
  ],
  resolve: {
    alias: {
      "@Tools": pathFn("src/tools/")
    }
  },
	output: {
    filename: '[name].bundle.[hash].js',
    chunkFilename: '[name].bundle.js',
    path: path.resolve(__dirname, outputPath),
  },
	   module: {
     rules: [
       {
         test: /\.css$/,
         use: [
           'style-loader',
           'css-loader'
         ]
       },
       {
         test: /\.(png|svg|jpg|gif)$/,
         use: [
           {
            loader: 'file-loader',
            options: {
              outputPath: "images/"
            }
           }
         ]
       },
       {
         test: /\.(woff|woff2|eot|ttf|otf)$/,
         use: [
           'file-loader'
         ]
       },
       {
         test: /\.(csv|tsv)$/,
         use: [
           'csv-loader'
         ]
       },
       {
         test: /\.xml$/,
         use: [
           'xml-loader'
         ]
       }
     ]
   }
}